﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System;

#if UNITY_EDITOR
public class AssetBundleDistributer
{
    [MenuItem("Test/Distribute")]
    static void DistributeTest()
    {
        PlayerSettings.distributeAssetBundle = true;
        BuildPipeline.BuildAssetBundles("AssetBundles/StandaloneOSXUniversal", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSX);
        PlayerSettings.distributeAssetBundle = false;
    }

    public static void Run()
    {
        var arguments = System.Environment.GetCommandLineArgs();
        var shoudRebuild = Array.IndexOf(arguments, "-forceRebuild") > 0;

        var buildOptions = BuildAssetBundleOptions.None;
        if (shoudRebuild)
            buildOptions |= BuildAssetBundleOptions.ForceRebuildAssetBundle;
        

        if (Array.IndexOf(arguments, "-distributedMaster") > 0)
        {
            PlayerSettings.distributeAssetBundle = true;
        }

        BuildPipeline.BuildAssetBundles("AssetBundles/StandaloneOSXUniversal", buildOptions, BuildTarget.StandaloneOSX);

        if (Array.IndexOf(arguments, "-distributedMaster") > 0)
        {
            PlayerSettings.distributeAssetBundle = false;
        }
    }
}

#endif